package com.labichaoka.chaoka.widget.wheel.adapters;

import android.content.Context;

import java.util.List;

/**
 * Created by wangjie on 9/18/16.
 */
public class ListWheelAdapter<T> extends AbstractWheelTextAdapter {


    private final List<T> itemsList;

    public ListWheelAdapter(Context context, List<T> itemsList) {
        super(context);
        this.itemsList = itemsList;
    }

    @Override
    public CharSequence getItemText(int index) {
        if (index >= 0 && index < itemsList.size()) {
            T item = itemsList.get(index);
            if (item instanceof CharSequence) {
                return (CharSequence) item;
            }
            return item.toString();
        }
        return null;
    }

    @Override
    public int getItemsCount() {
        return itemsList.size();
    }
}
